﻿/// <reference path="RequestHandler.js" />
/// <reference path="../HttpRequest.js" />
/// <reference path="../../utilities/FXDom.js" />
/// <reference path="../../utilities/Markup.js" />
///--------------------------------------------------------------------
/// <file name="PostHandler.js">
///   Adds markup buttons to the normal thread post screen.
/// </file>
///--------------------------------------------------------------------

NAMFox.ns(function() { with (NAMFox) {

this.PostHandler = function() {
};

PostHandler.prototype = new RequestHandler();
PostHandler.prototype.name = "PostHandler";

PostHandler.prototype.handleRequestCore = function(request, _$) {
    /// <summary>Handles a request.</summary>
    /// <param name="request" type="HttpRequest">
    ///   The HTTP request which encapsulates the
    ///   document and route data for this request.
    /// </param>

    var textArea = _$("#post_textarea");

    if (textArea.length === 1) {
        request.htmlDocument.__namfox__.textArea = textArea;

        if (!textArea.val()) {
            textArea.val($.messages.getDefaultMessage().text);
        }
        else if (request.htmlDocument.location.href.match(/qt=\d+/)) {
            var element = textArea.get(0);
            var close = textArea.val().length;
            element.setSelectionRange(close, close);
            Markup.addText("\n\n" + $.messages.getDefaultMessage().text, textArea);
        }

        _$("#editbuttons").append(
            Markup.create(
                textArea,
                MarkupLocation.Post,
                Markup.strike,
                Markup.anchor,
                Markup.profile,
                Markup.privateMessageLink,
                Markup.replace,
                Markup.indent,
                Markup.superscript,
                Markup.subscript,
                Markup.code,
                Markup.php,
                Markup.pre,
                Markup.horizontalRule,
                Markup.videos,
                Markup.customMessages
            )
        );
    }
};

}});